package com.tts.superstar.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.tts.superstar.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class kechengFragment extends Fragment {


    List<Map> list;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_kecheng, container, false);
        initData();
        ListView listView = view.findViewById(R.id.lv_kecheng);
        MyAdapter myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);

        return view;
    }


    private void initData() {
        list = new ArrayList<>();
        String[] strings = {"小升初中古诗词分类汇总", "高中语文诗词鉴赏", "诗词鉴赏答题技巧","每日学英语","答题技巧","你号没了","今天元气满满","每日高数","作文精选","我很强","今天你学习了吗","我还能更强","每日精选"};
        String[] strings2= {"全东语","鲁迅整理","那卡编辑","李冬梅","佘余","余余","佘佘","小明","小华","小红","小李","小王","小东"};
        String[] strings3= {"收藏563","收藏695","收藏45","收藏53","收藏65","收藏453","收藏645","收藏163","收藏895","收藏345","收藏163","收藏865","收藏845"};
        int[] ints = {R.mipmap.re_1, R.mipmap.re_2, R.mipmap.re_3, R.mipmap.re_4, R.mipmap.re_5
                , R.mipmap.re_6, R.mipmap.re_7, R.mipmap.re_8, R.mipmap.re_9, R.mipmap.re_10, R.mipmap.huodong7, R.mipmap.huodong6, R.mipmap.huodong5};

        for (int i = 0; i < 13; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("img", ints[i]);
            map.put("text", strings[i]);
            map.put("text2", strings2[i]);
            map.put("text3", strings3[i]);
            list.add(map);
        }
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_resource, parent, false);


            Map<String, Object> map = list.get(position);
            ImageView imageView = convertView.findViewById(R.id.tv_zt1);
            imageView.setBackgroundResource(Integer.parseInt(map.get("img") + ""));

            TextView textView = convertView.findViewById(R.id.tv_zt2);
            textView.setText(map.get("text") + "");

            TextView textView1 = convertView.findViewById(R.id.tv_zt3);
            textView1.setText(map.get("text2") + "");

            TextView textView2 = convertView.findViewById(R.id.tv_zt4);
            textView2.setText(map.get("text3") + "");

            return convertView;
        }
    }


}
